/*******************************************************************************
 * CLASS		PBDataStruct
 * AUTHOR		John Paul Swaynos
 * DESCRIPTION
 * This class is the data structure that is used by the Photo Mode to "store" 
 * the photos. When an image is capture in photo mode it stores the username,
 * and the filepath of the photo to a linked list.
 ******************************************************************************/
#include "PBDataStruct.h"
#include <Windows.h>
PBDataStruct::PBDataStruct() {
	firstName = nullptr;
	lastName = nullptr;
	filepath = nullptr;
	next = nullptr;
}
PBDataStruct::PBDataStruct(char* firstName, char* lastName, char* filepath){
	this->firstName = firstName;
	this->lastName = lastName;
	this->filepath = filepath;
	next = nullptr;
}
PBDataStruct::PBDataStruct(char* firstName, char* lastName, char* filepath, PBDataStruct * next) {
	this->firstName = firstName;
	this->lastName = lastName;
	this->filepath = filepath;
	this->next = next;
}
void PBDataStruct::setFirstName(char* firstName) {
	this->firstName = firstName;
}
char* PBDataStruct::getFirstName() {
	return firstName;
}
void PBDataStruct::setLastName(char* lastName) {
	this->lastName = lastName;
}
char* PBDataStruct::getLastName() {
	return lastName;
}
void PBDataStruct::setFilepath(char* filepath) {
	this->filepath = filepath;
}
char* PBDataStruct::getFilepath() {
	return filepath;
}
void PBDataStruct::setNextLink(PBDataStruct * next) {
	this->next = next;
}
PBDataStruct * PBDataStruct::getNextLink(){
	return next;
}
void PBDataStruct::insert(PBDataStruct * node) {
	PBDataStruct * currentLink = nullptr;
	PBDataStruct * nextLink = nullptr;
	currentLink = this;
	nextLink = next;
	while(nextLink != nullptr) {
		currentLink = nextLink;
		nextLink = currentLink->next;
	}
	currentLink->setNextLink(node);
}
PBDataStruct * PBDataStruct::find(char * firstName, char * lastName) {
	PBDataStruct * currentLink = nullptr;
	PBDataStruct * nextLink = nullptr;
	currentLink = this;
	// check to make sure not nullptr
	if (currentLink == nullptr)
		return nullptr;
	nextLink = next;
	while(nextLink != nullptr) {
		char * currentFirstName = currentLink->getFirstName();
		char * currentLastName = currentLink->getLastName();
		if (strcmp(currentFirstName, firstName) == 0 && strcmp(currentLastName, lastName) == 0) {
			return currentLink;
		}
		currentLink = nextLink;
		nextLink = currentLink->next;
	}
	// The L.L. could possibly be only one node, check the one node
	char * currentFirstName = currentLink->getFirstName();
	char * currentLastName = currentLink->getLastName();
	if (strcmp(currentFirstName, firstName) == 0 && strcmp(currentLastName, lastName) == 0) {
		return currentLink;
	}
	return nullptr;
}